package org.ms.mconf.sdk.service.support;

import lombok.*;
import org.ms.mconf.sdk.model.DataConfig;
import org.ms.mconf.sdk.model.MetaConfig;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class ChangeLog implements Serializable {

    private MetaConfig metaConfig;
    private List<DataConfig> dataConfigs;
    private List<DataConfig> oldDataConfigs;

    public static ChangeLog buildAddOrDelete(MetaConfig metaConfig, List<DataConfig> dataConfigs) {
        ChangeLog changeLog = new ChangeLog();
        changeLog.setMetaConfig(metaConfig);
        changeLog.setDataConfigs(dataConfigs);
        return changeLog;
    }

    public static List<ChangeLog> buildAdds(MetaConfig metaConfig, List<DataConfig> dataConfigs) {
        List<ChangeLog> changeLogs = new ArrayList<>();
        changeLogs.add(buildAddOrDelete(metaConfig, dataConfigs));
        return changeLogs;
    }

    public static List<ChangeLog> buildUpdates(MetaConfig metaConfig, List<DataConfig> dataConfigs, List<DataConfig> oldDataConfigs) {
        List<ChangeLog> changeLogs = new ArrayList<>();
        changeLogs.add(new ChangeLog(metaConfig, dataConfigs, oldDataConfigs));
        return changeLogs;
    }

}
